package com.william.jdbcplus.core.dialects.pagination.impl;

import com.william.jdbcplus.core.dialects.pagination.IPagination;

/**
 * ORACLE 数据库分页语句组装实现
 *
 * @author niliwei
 */
public class OraclePagination implements IPagination {

    @Override
    public String getPaginationSql(String originalSql, long offset, long limit) {
        limit = (offset >= 1) ? (offset + limit) : limit;
        long offsetParam = offset;
        long limitParam = limit;
        String sql = "SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( " + originalSql + " ) TMP WHERE ROWNUM <=" + limitParam + ") WHERE ROW_ID > "
                + offsetParam;
        return sql;
    }
}
